package com.bsoft.wx.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bsoft.wx.pojo.TbUser;
import org.apache.ibatis.annotations.Select;

import java.util.HashMap;
import java.util.Set;

/**
 * <p>
 * 用户表 Mapper 接口
 * </p>
 *
 * @author hdh
 * @since 2023-01-11
 */

public interface TbUserMapper extends BaseMapper<TbUser> {
    @Select("SELECT IF(COUNT(*),TRUE,FALSE ) from tb_user where  root=1")
    public boolean haveRootUser1();

    public int insert(HashMap param);

    @Select(" SELECT p.permission_name\n" +
            "        FROM tb_user u\n" +
            "        JOIN tb_role r ON JSON_CONTAINS(u.role, CAST(r.id AS CHAR))\n" +
            "        JOIN tb_permission p ON JSON_CONTAINS(r.permissions, CAST(p.id AS CHAR))\n" +
            "        WHERE u.id = #{userId} AND u.status = 1;")
    public Set<String> searchUserPermissions(int UserId);

    @Select("SELECT id FROM  tb_user WHERE open_id=#{openId} and status=1")
    public Integer searcherByOpenId(String openId);
}
